package com.tsingteng.cosfun.ui.cosfun.presenter;

import android.util.Log;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.ParagraphBean;
import com.tsingteng.cosfun.bean.PersonBean;
import com.tsingteng.cosfun.bean.PlayBean;
import com.tsingteng.cosfun.bean.PullBlackBean;
import com.tsingteng.cosfun.bean.VidePersonBean;
import com.tsingteng.cosfun.bean.WorkBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonCenterContract;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonWorkContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.PersonCenterModel;
import com.tsingteng.cosfun.ui.cosfun.imodel.PersonWorkModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PersonWorkPresenter extends BasePresenter<PersonWorkContract.IPersonWorkrView> implements PersonWorkContract.IPersonwork {

    PersonWorkModel personModel = null;
    PersonWorkContract.IPersonWorkrView iPersonView = null;

    public PersonWorkPresenter(PersonWorkContract.IPersonWorkrView iPersonCenterView) {
        this.personModel = new PersonWorkModel();
        this.iPersonView = iPersonCenterView;
    }


    @Override
    public void loginFollowFans(String follow_id, int position) {
        iPersonView.showLoading("");
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iPersonView.hideLoading();
                iPersonView.getFollowResult(response.body().data, position);
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iPersonView.hideLoading();
            }


        };

        personModel.getFollowNotification(follow_id, rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id, int position) {
        iPersonView.showLoading("");
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iPersonView.hideLoading();
                iPersonView.getFollowResult(response.body().data, position);
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iPersonView.hideLoading();
            }


        };

        personModel.getNoFollowNotification(follow_id, rxObserver);
    }

    @Override
    public void getParagraphList(long userId, String page_no, String page_size) {
        iPersonView.showLoading("");
        Callback<BaseDataBean<PlayBean>> paraCallback = new Callback<BaseDataBean<PlayBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<PlayBean>> call, Response<BaseDataBean<PlayBean>> response) {
                iPersonView.hideLoading();
                iPersonView.showParagraphData(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<PlayBean>> call, Throwable t) {
                iPersonView.hideLoading();
            }
        };
        personModel.getParagraphList(userId, page_no, page_size, paraCallback);
    }

    @Override
    public void getParagraphLikeList(long userId, String page_no, String page_size) {
        iPersonView.showLoading("");
        Callback<BaseDataBean<PlayBean>> paraCallback = new Callback<BaseDataBean<PlayBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<PlayBean>> call, Response<BaseDataBean<PlayBean>> response) {
                iPersonView.hideLoading();
                iPersonView.showParagraphData(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<PlayBean>> call, Throwable t) {
                iPersonView.hideLoading();
            }
        };
        personModel.getParagraphLikeList(userId, page_no, page_size, paraCallback);
    }


    @Override
    public void getWorkList(long userId, String c, String showType, String page_no, String page_size, String deviceId) {
        iPersonView.showLoading("");
        Callback<BaseDataBean<VidePersonBean>> workCallback = new Callback<BaseDataBean<VidePersonBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<VidePersonBean>> call, Response<BaseDataBean<VidePersonBean>> response) {
                iPersonView.hideLoading();
                if ( null == response.body()){
                    return;
                }
                iPersonView.shoWorkData(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<VidePersonBean>> call, Throwable t) {
                iPersonView.hideLoading();
            }
        };
        personModel.getWorkList(userId, c, showType, page_no, page_size, deviceId, workCallback);
    }

    @Override
    public void getPraiseOrNotData(String praise_type, String id, String type,int position) {
        iPersonView.showLoading("");

        Callback<BaseDataBean<Integer>> callback = new Callback<BaseDataBean<Integer>>() {
            @Override
            public void onResponse(Call<BaseDataBean<Integer>> call, Response<BaseDataBean<Integer>> response) {
                iPersonView.hideLoading();
                iPersonView.showPraiseResult(response.body().data, position);
            }

            @Override
            public void onFailure(Call<BaseDataBean<Integer>> call, Throwable t) {
                iPersonView.hideLoading();
                iPersonView.showFail(t.getMessage());
            }
        };
        personModel.getPraiseOrNot(praise_type, id, type, callback);
    }


    @Override
    public void getDelPlay(String paragraph_id, int position) {
        Callback<BaseDataBean<String>> rxObserver = new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {
                iPersonView.showDelResult(response.body(),position);
            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {
                iPersonView.showFail(t.getMessage());
            }


        };

        personModel.getDelPlay(paragraph_id,rxObserver);
    }

    @Override
    public void getAddNotLikePlay(String paragraph_id, int position) {
        Callback<BaseDataBean<String>> rxObserver = new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {
                iPersonView.ShowNotLiketResult(response.body(),position);
            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {
                iPersonView.showFail(t.getMessage());
            }


        };

        personModel.getAddNotLikePlay(paragraph_id,rxObserver);
    }

    @Override
    public void getCancelPullBlack(long user_id) {
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                PullBlackBean body = response.body();
                int data = body.getData();
                iPersonView.showCancelPullBlack(data);
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                Log.e("/////", t.getMessage());
            }
        };
        personModel.getCancelPullBlackInfo(user_id, workCallback);
    }
}
